package Lambda.Predicate;

import java.util.ArrayList;
import java.util.function.Predicate;

public class Predicatedemo3 {
    private static ArrayList<String> filter(String[] arr, Predicate<String> p1,Predicate<String> p2){
        //创建一个集合来存取满足条件的数据；
        ArrayList<String> list = new ArrayList<>();
        //遍历数组，进行筛选
        for (String s : arr) {
            boolean f=p1.and(p2).test(s);
            if (f){
                list.add(s);
            }
        }
        return list;
    }

    public static void main(String[] args) {
        String[] arr={"赵丽颖，女","科比，男","詹姆斯，男"};
       ArrayList<String> list= filter(arr,(s)->{
            String s1 = s.split("，")[1];
            return s1.equals("男");
        },(s)->{
           return s.split("，")[0].length()<5;
        });
        for (String s : list) {
            System.out.println(s);
        }
    }


}
